package com.lxu.jdbcThreadlocal.service;

import com.lxu.jdbc.dao.JDBCDao;
import com.lxu.jdbc.utils.JDBCUtil;
import com.lxu.jdbcThreadlocal.dao.JDBCDao2;
import com.lxu.jdbcThreadlocal.utils.JDBCUtil2;

import java.sql.Connection;

public class CommonService2 {

    public void transfer(String inUser, String outUser, int money) {
        Connection conn = null;
        try {
            conn = JDBCUtil.getConnection();
            conn.setAutoCommit(false);
            JDBCDao2 jdbcDao2 = new JDBCDao2();
            jdbcDao2.out(inUser, money);
            int i = 1 / 0;
            jdbcDao2.in(outUser, money);
            JDBCUtil2.commitAndClose(conn);
        } catch (Exception e) {
            e.printStackTrace();
            if (conn != null) {
                JDBCUtil.rollbackAndClose(conn);
            }
        }
    }

}
